package com.umeox.zikrringtest

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.*
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.umeox.auto_light.AutoLightActivity
import com.umeox.auto_update.AutoUpdateConfigureActivity
import com.umeox.zikrringtest.single_test.SearchActivity

class MainActivity : AppCompatActivity() {

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val tv = findViewById<TextView>(R.id.tv)
        tv.text = "iQibla测试工具\nV${getVerName(this)}"

        val btSingle: Button = findViewById(R.id.bt_single)
        val btSensor: Button = findViewById(R.id.bt_sensor)
        val btAuto: Button = findViewById(R.id.bt_auto)
//        val btLight: Button = findViewById(R.id.bt_light)
//        val btAutoClose: Button = findViewById(R.id.bt_auto_close)

        btSingle.setOnClickListener {
            startActivity(Intent(this, SearchActivity::class.java).apply {
                putExtra("type", 1)
            })
        }

        btSensor.setOnClickListener {
            startActivity(Intent(this, SearchActivity::class.java).apply {
                putExtra("type", 2)
            })
        }

        btAuto.setOnClickListener {
            startActivity(Intent(this, AutoUpdateConfigureActivity::class.java))
            finish()
        }

//        btLight.setOnClickListener {
//            startActivity(Intent(this, AutoLightActivity::class.java))
//            finish()
//        }
//
//        btAutoClose.setOnClickListener {
//            startActivity(Intent(this, AutoCloseActivity::class.java))
//            finish()
//        }
    }

    private fun getVerName(context: Context): String {
        var verName = ""
        try {
            verName = context.packageManager.getPackageInfo(
                context.packageName, 0
            ).versionName
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return verName
    }
}